package com.hgyc.mom.mes.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgyc.mom.common.vo.Result;
import com.hgyc.mom.core.mybatis.QueryWrapperUtil;
import com.hgyc.mom.mes.entity.SopSendRecord;
import com.hgyc.mom.mes.service.SopSendRecordService;
import com.hgyc.mom.mes.vo.SopSendRecordParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 推送记录 Controller
 *
 * @author fwj
 * @since 2025-06-27
 */
@Tag(name = "推送记录 控制器", description = "推送记录 控制器")
@RestController
@RequestMapping("/mes/record")
public class SopSendRecordController {
    @Autowired
    private SopSendRecordService sopSendRecordService;

    @Operation(summary = "查询推送记录 列表", description = "查询推送记录 列表")
    @PostMapping("/pageList")
    public Result<IPage<SopSendRecord>> pageList(@Parameter(description = "查询参数") @RequestBody SopSendRecordParam sopSendRecordParam) {
        Page<SopSendRecord> page = new Page<>(sopSendRecordParam.getPage(), sopSendRecordParam.getPageSize());
        SopSendRecord sopSendRecord = new SopSendRecord();
        BeanUtils.copyProperties(sopSendRecordParam, sopSendRecord);
        QueryWrapper<SopSendRecord> wrapper = QueryWrapperUtil.build(sopSendRecord);
        IPage<SopSendRecord> list = sopSendRecordService.page(page, wrapper);
        return Result.success(list);
    }

    @Operation(summary = "获取推送记录 详细信息", description = "获取推送记录 详细信息")
    @GetMapping(value = "/{id}")
    public Result getInfo(@Parameter(description = "推送记录 ID") @PathVariable("id") Long id) {
        return Result.success(sopSendRecordService.getById(id));
    }
    @Operation(summary = "新增推送记录 ", description = "新增推送记录 ")
    @PostMapping
    public Result<?> save(@Parameter(description = "推送记录 ") @RequestBody SopSendRecord sopSendRecord) {
        sopSendRecordService.saveRecord(sopSendRecord);
        return Result.success();
    }

    @Operation(summary = "修改推送记录 ", description = "修改推送记录 ")
    @PutMapping
    public Result<?> update(@Parameter(description = "推送记录 ") @RequestBody SopSendRecord sopSendRecord) {
        sopSendRecordService.updateRecord(sopSendRecord);
        return Result.success();
    }

    @Operation(summary = "删除推送记录 ", description = "删除推送记录 ")
    @DeleteMapping
    public Result<?> remove(@Parameter(description = "删除ID") @RequestParam("ids") Long[] ids) {
        return Result.success(sopSendRecordService.removeByIds(Arrays.asList(ids)));
    }

}
